
$(function(){
    $('#file').change(function () {
        var imgUrl = $(this).val();
        $('.file').val(imgUrl);
        uploadImage();
    });
});

function uploadImage() {
    var formData = new FormData($("#uploadForm")[0]);
    var url = linkPath + 'smartfire/wx/file/upload/img';
    $.ajax({
        url: url,
        type: 'POST',
        data: formData,
        beforeSend: function(request) {
            request.setRequestHeader("ACCESS-TOKEN", token);
        },
        async: false,
        cache: false,
        contentType: false,
        processData: false,
        success: function(res) {
            if(res.success){
                $("#attachment").html(res.obj.fileName);
                myAlert("上传成功!")
            }else {
                myAlert("上传失败!")
            }
        },
        error: function(error) {
            console.log(error);
        }
    });
}